<template>
	<div class="search">
		<SearchTools ref="searchtools" :keyword="key" v-on:searchInitCommunications="searchInitCommunications" v-on:searchResultListHandle="searchResultListHandle" :pgnum="pgnum" />
		<SearchResultList :searchResultList="searchResultList" v-on:searchMoreCommunications="searchMoreCommunications" :pgnum="pgnum" />
	</div>
</template>

<script>
	import SearchTools from "../../components/search/search-tools.vue";
	import SearchResultList from "../../components/search/search-result-list.vue";
	export default {
		name:"Search",
		data:function(){
			return{
				key: decodeURIComponent(this.$route.params.key),
				searchResultList:[],
				type: "1",
				pgnum: 1
			}
		},
		components:{
			SearchTools,
			SearchResultList
		},
		created:function(){
			//console.log(this.$route.params, this.key)
			this.$emit("upLocalData", [{
				name: "type",
				value: "search"
			},{
				name: "channelName",
				value: "搜索"
			}]);
		},
		watch:{
			$route: function(){
				window.scrollTo(1,1);
				location.reload();
			}
		},
		methods:{
			searchResultListHandle(list, type, key){
				//console.log(list, type, key)
				let pgn = this.pgnum+1;
				this.$set(this, "pgnum", pgn);
				this.$set(this, "key", key);
				this.$set(this, "type", type);
				this.$set(this, "searchResultList", this.searchResultList.concat(list));
			},
			searchMoreCommunications(args){
				//console.log(this.pgnum)
				if (this.pgnum <= 3) {
					this.$refs.searchtools.searchRequest(this.key, this.type);
				}
			},
			searchInitCommunications(args){
				this.$set(this, "searchResultList", []);
				this.$set(this, "pgnum", 1);
				this.$set(this, "key", "");
				this.$set(this, "type", "1");
			}
		}
	}
</script>

<style lang="less">
	@base:23.44/1rem;
	.search{
		
	}
</style>
